package chat

import (
	"fmt"
	"github.com/gogf/gf/v2/os/gctx"
	"time"
	"xr-game-server/core/cache"
)

var chatCache = cache.NewCacheMgr()

func chkCD(roleId uint64, typeId int) *time.Time {
	key := fmt.Sprintf("chatdto:cd:%v:%v", roleId, typeId)
	val, _ := chatCache.Cache.Get(gctx.New(), key)
	if val == nil {
		now := time.Now().Add(CD)
		chatCache.FlushCache(key, now)
		return nil
	}
	ret := val.Val()
	return ret.(*time.Time)
}

func flushCD(roleId uint64, typeId int) {
	now := time.Now().Add(CD)
	chatCache.FlushCache(fmt.Sprintf("chatdto:cd:%v:%v", roleId, typeId), &now)
}
